﻿using UnityEngine;
using System.Collections;
using CHFramework;
using UnityEngine.UI;
using System;

public class UIMainPanel : BaseUI 
{
    public GameObject ShopBtn;
    public GameObject SettingBtn;
    public GameObject QuestBtn;
    public GameObject StartBtn;

    private void Awake()
    {
        base.CurrentUIType.PanelType = UIPanelType.Normal;
        base.CurrentUIType.ShowMode = UIPanelShowMode.HideOther;
        
        EventTriggerListener.Get(StartBtn).onClick = OnStartGame;
        EventTriggerListener.Get(ShopBtn).onClick = OnEnterShop;
        EventTriggerListener.Get(SettingBtn).onClick = OnEnterSetting;
        EventTriggerListener.Get(QuestBtn).onClick = OnEnterQuest;
    }

    /// <summary>
    /// 打开商店
    /// </summary>
    /// <param name="sender"></param>
    public void OnEnterShop(GameObject sender)
    {
        UIManager.Instance.ShowUIPanel(EnumPanel.UIShopPanel);
    }

    #region 测试增加金币
    private void OnAdd(GameObject sender)
    {
        EventData evt = new EventData(SysDefine.UpdateCash, 1, 1000);
        EventManager.Instance.EventDispatch(evt);

        EventData evt2 = new EventData(SysDefine.UpdateCoin, 1, 85);
        EventManager.Instance.EventDispatch(evt2);
    }

    private void OnCut(GameObject sender)
    {
        EventData evt = new EventData(SysDefine.UpdateCash, 1, -100);
        EventManager.Instance.EventDispatch(evt);

        EventData evt2 = new EventData(SysDefine.UpdateCoin, 1, -185);
        EventManager.Instance.EventDispatch(evt2);
    } 
    #endregion


    /// <summary>
    /// 开始游戏
    /// </summary>
    /// <param name="sender"></param>
    private void OnStartGame(GameObject sender)
    {
        UIManager.Instance.LoadSceneSync("GamePlay", null, null, () => {
            UIManager.Instance.ShowUIPanel(EnumPanel.UIInGamePanel);
        });
    }

    /// <summary>
    /// 打开任务
    /// </summary>
    /// <param name="sender"></param>
    private void OnEnterQuest(GameObject sender)
    {

    }

    /// <summary>
    /// 打开设置
    /// </summary>
    /// <param name="sender"></param>
    private void OnEnterSetting(GameObject sender)
    {
        UIManager.Instance.ShowUIPanel(EnumPanel.UISettingPanel);
    }
}
